package cn.yunhe.service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import cn.yunhe.dao.impl.GoodsDaoImpl;
import cn.yunhe.entity.Goods;
import cn.yunhe.entity.Page;
@Service
public class PageService {
	@Autowired
	private GoodsDaoImpl gd;

	public Page<Goods> getPage(int currentPage) {

		Page<Goods> page = new Page<Goods>();

		int count = gd.getCount();
		int pageMax = page.getPageMax();
		int pageCount = count % pageMax == 0 ? count / pageMax : count / pageMax + 1;
		Map<String, Object> map = new HashMap<String, Object>();
		int start = (currentPage - 1) * pageMax;
		// oracle分页end
		// int end = start + pageMax - 1;
		// mysql分页end
		int end = pageMax;
		map.put("start", start);
		map.put("end", end);
		List<Goods> glist = gd.getPageList(map);
		System.out.println("-----service打印数据库数据");
		for (Goods goods : glist) {
			// System.out.println(goods.toString());
		}
		page.setCount(count);
		page.setCurrentPage(currentPage);
		page.setList(glist);
		page.setPageCount(pageCount);
		return page;
	}

	public int deleteGoods(int gid) {
		int result = 0;

		result = gd.deleteGoods(gid);
		return result;
	}

	public int addGoods(Goods goods) {
		int result = 0;

		result = gd.addGoods(goods);
		return result;
	}

	public int modifyGoods1(Goods goods) {
		int result = 0;
		result = gd.editGoods1(goods);
		return 0;
	}

	public int modifyGoods2(Goods goods) {
		int result = 0;
		result = gd.editGoods2(goods);
		return 0;
	}

}
